home *** CD-ROM | disk | FTP | other *** search
- //____________________________________________________________
- // MovieLooping.c
- //
- // Copyright © Dan Parks Sydow, 1995
- // From the book:
- // "Graphics and Sound Programming Techniques for the Mac",
- // M&T Books, 1995
-
-
- //____________________________________________________________
-
- #include <Movies.h>
-
-
- //____________________________________________________________
-
- void InitializeAllToolboxes( void );
-
-
- //____________________________________________________________
-
- #define rMovieWindow 128
- #define kMovieName "\pRobot"
-
-
- //____________________________________________________________
-
- void main( void )
- {
- OSErr theError;
- FSSpec theFSSpec;
- short theFileRefNum;
- Movie theMovie;
- short theMovieResID = 0;
- Str255 theMovieResName;
- Boolean wasAltered;
- WindowPtr theWindow;
- Rect theMovieBox;
- Rect theBoundsRect;
- MovieController theController = nil;
- EventRecord theEvent;
- Boolean isControllerEvent;
- Boolean allDone = false;
-
- InitializeAllToolboxes();
-
- theError = FSMakeFSSpec( 0, 0, kMovieName, &theFSSpec );
- theError = OpenMovieFile( &theFSSpec, &theFileRefNum, fsRdPerm );
- theError = NewMovieFromFile( &theMovie, theFileRefNum, &theMovieResID,
- theMovieResName, newMovieActive, &wasAltered );
-
- CloseMovieFile( theFileRefNum );
-
- theWindow = GetNewCWindow( rMovieWindow, nil, (WindowPtr)-1L );
-
- SetMovieGWorld( theMovie, (CGrafPtr)theWindow, nil );
-
- GetMovieBox( theMovie, &theMovieBox );
-
- theController = NewMovieController( theMovie, &theMovieBox, mcTopLeftMovie);
-
- MCDoAction( theController, mcActionSetLooping, (Ptr)true ); // ** NEW CODE **
-
- MCGetControllerBoundsRect( theController, &theBoundsRect );
-
- SizeWindow( theWindow, theBoundsRect.right, theBoundsRect.bottom, true );
- ShowWindow( theWindow );
-
- while ( allDone == false )
- {
- WaitNextEvent( everyEvent, &theEvent, 15L, nil );
-
- if ( theController == nil )
- isControllerEvent = false;
- else
- isControllerEvent = MCIsPlayerEvent( theController, &theEvent );
-
- if ( isControllerEvent == false )
- {
- switch ( theEvent.what )
- {
- case keyDown:
- allDone = true;
- break;
- }
- }
- }
-
- DisposeMovieController( theController );
- theController = nil;
- DisposeMovie( theMovie );
- DisposeWindow( theWindow );
- }
-
-
- //____________________________________________________________
-
- void InitializeAllToolboxes( void )
- {
- OSErr theError;
- long theResult;
-
- InitGraf( &qd.thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( 0L );
- FlushEvents( everyEvent, 0 );
- InitCursor();
-
- theError = Gestalt( gestaltQuickTime, &theResult );
- if ( theError != noErr )
- ExitToShell();
-
- theError = EnterMovies();
- if ( theError != noErr )
- ExitToShell();
- }
-
-
-
-